package ru.spbsu.electromenu.model;

import ru.spbsu.electromenu.util.collections.Idable;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Date: 3/19/11
 * Time: 5:04 PM
 *
 * @author Artem Titov
 */
public class Order implements Idable {
    private int id = -1;
    private Date time = null;
    private int sessionId = -1;
    private boolean confirmed = false;
    private Map<Integer, Integer> orderedDishesIds = null;
    private List<OrderedDish> orderedDishes = null;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public int getSessionId() {
        return sessionId;
    }

    public void setSessionId(int sessionId) {
        this.sessionId = sessionId;
    }

    public boolean isConfirmed() {
        return confirmed;
    }

    public void setConfirmed(boolean confirmed) {
        this.confirmed = confirmed;
    }

    public Map<Integer, Integer> getOrderedDishesIds() {
        return orderedDishesIds;
    }

    public List<OrderedDish> getOrderedDishes() {
        return orderedDishes;
    }

    public void setOrderedDishesIds(Map<Integer, Integer> orderedDishesIds) {
        this.orderedDishesIds = orderedDishesIds;
    }

    public void injectDishes(Map<Integer, Dish> dishes) {
        orderedDishes = new ArrayList<OrderedDish>();
        for (final Integer orderedDishId : orderedDishesIds.keySet()) {
            final OrderedDish orderedDish = new OrderedDish();
            orderedDish.setOrder(this);
            orderedDish.setDish(dishes.get(orderedDishId));
            orderedDish.setAmount(orderedDishesIds.get(orderedDishId));
            orderedDishes.add(orderedDish);
        }
    }
}
